class ListController {

    def index = { }
    
    def nAirport2nTrain = {
    	flash.message = ""
    	
    	if (params.personId) {
    		def person = Sportsman.get(params.personId)
        	person.nAirportComeAt = new Date(0)
        	person.save()
        	flash.message = "移除運動員 ${person.name} 紀錄"
    	}
    	
    	def people = Sportsman.findAll("from Sportsman as m where m.nAirportComeAt > ? and m.nTrainComeAt = ?", [new Date(0), new Date(0)])
    	people.sort {
    		it.nAirportComeAt
    	}
    	[people:people]
    }
    
    // method ------------------------------------
    def genPredictDates(people, minute) {
    	def predictDates = [:]
    	people.each {
	    	def calendar = Calendar.getInstance()
	    	calendar.setTime(it.nAirportComeAt)
	    	calendar.add(Calendar.MINUTE, minute)
	    	predictDates[it.uid] = calendar
    	}
    	return predictDates
    }
}
